package com.raising.modules.cms.service;

import com.raising.StaticParam;
import com.raising.framework.service.CrudService;
import com.raising.modules.cms.dao.CmsArticleDao;
import com.raising.modules.cms.entity.CmsArticle;
import com.raising.utils.JStringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* 文章表 Service层
* @author luxy
* @createTime 2018-01-20 19:12:39
*/
@Service
@Transactional(rollbackFor = Exception.class)
public class CmsArticleService extends CrudService<CmsArticleDao, CmsArticle> {
    /**
     * 根据id修改文章点击量
     * @author chenem
     * @param cmsArticle
     * @return
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    public int updateCmsArticleHitsById(CmsArticle cmsArticle) throws Exception {
        if (null != cmsArticle) {
            if (JStringUtils.isNotBlank(cmsArticle.getId())) {
                //如果id非空则将点击量+1，并更新点击量
                cmsArticle.setHits(String.valueOf(Integer.parseInt(cmsArticle.getHits()) + 1));
                return dao.updateHitsById(cmsArticle);
            }
        }
        return StaticParam.NO;
    }

}
